import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:yeild_libs_rfid_android/yeild_libs_rfid_android.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:yeild_libs_rfid_platform_interface/yeild_libs_rfid_method_channel.dart';
import 'package:yeild_libs_rfid_platform_interface/yeild_libs_rfid_platform_interface.dart';

class MockYeildLibsRfidAndroid
    with MockPlatformInterfaceMixin
    implements YeildLibsRfidAndroid {
  static void registerWith() {
    RfidPlatformInterface.instance = MockYeildLibsRfidAndroid();
  }

  @override
  Future<String?> getPlatformVersion() => Future.value('42');
}

void main() {
  TestWidgetsFlutterBinding.ensureInitialized();
  group(YeildLibsRfidAndroid, () {
    const channel = MethodChannel('plugins.libs.yeild.com/rfid_android');
    setUp(() async {
      TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
          .setMockMethodCallHandler(channel, (MethodCall methodCall) async {
            if (methodCall.method == 'getPlatformVersion') {
              return '42';
            }
            throw UnimplementedError('Unknow method ${methodCall.method}');
          });
    });
    tearDown(() {
      TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
          .setMockMethodCallHandler(channel, null);
    });
    final RfidPlatformInterface initialPlatform =
        RfidPlatformInterface.instance;

    test('$RfidPlatformInterface is the default instance', () {
      expect(initialPlatform, isInstanceOf<YeildLibsRfidDefault>());
    });

    YeildLibsRfidAndroid.registerWith();
    test('register instance', () {
      expect(RfidPlatformInterface.instance, isA<YeildLibsRfidAndroid>());
    });

    RfidPlatformInterface plugin = RfidPlatformInterface.instance;
    test('getPlatformVersion', () async {
      expect(await plugin.getPlatformVersion(), '42');
    });
  });
}
